package com.ynunicom.dc.dingdingcontractapp.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.ynunicom.dc.dingdingcontractapp.entity.requestbodyentity.TransBody;
import com.ynunicom.dc.dingdingcontractapp.service.AdminOptionService;
import com.ynunicom.dc.dingdingcontractapp.utils.AppInfoUtil;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * @author: jinye.Bai
 * @date: 2020/5/25 17:46
 */
@Service
public class AdminOptionServiceImpl implements AdminOptionService {

    @Resource
    RestTemplate restTemplate;

    private static final String ADMIN_LIST_URL = "https://oapi.dingtalk.com/user/get_admin?access_token={access_token}";

    private static final String ADMIN_SCOPE_URL = "https://oapi.dingtalk.com/topapi/user/get_admin_scope?access_token={access_token}&userid={userid}";

    @Override
    public JSONObject getAdminList(TransBody transBody) {
        Map<String,String> urlVar = new HashMap<>(1);
        urlVar.put("access_token",transBody.getAccess_token());
        return restTemplate.getForObject(ADMIN_LIST_URL,JSONObject.class,urlVar);
    }

    @Override
    public JSONObject getAdminScope(TransBody<String> transBody) {
        Map<String,String> urlVar = new HashMap<>(2);
        urlVar.put("access_token",transBody.getAccess_token());
        urlVar.put("userid",transBody.getRequestBody());
        return restTemplate.getForObject(ADMIN_SCOPE_URL,JSONObject.class,urlVar);
    }
}
